#ifndef _COM_DEF_H_
#define _COM_DEF_H_

#include "stdint.h"

#define COM_BUFF_SIZE 256

typedef enum
{
    COM_RX_IDLE, //!< Receiver is in idle state.
    COM_RX_RCV,  //!< Frame is beeing received.
    COM_RX_RCVEND,
    COM_RX_WAIT,
    COM_RX_TIMEOUT //!< Time out ,Send a command and no data return after 500ms( --> system timer)

} ComRcvState_t;

typedef enum
{
    COM_TX_IDLE, /*!< Transmitter is in idle state. */
    COM_TX_XMIT  /*!< Transmitter is in transfer state. */
} ComSndState_t;

typedef enum
{
    COM_PAR_NONE, /*!< No parity. */
    COM_PAR_ODD,  /*!< Odd parity. */
    COM_PAR_EVEN  /*!< Even parity. */
} ComParity_t;

typedef union {
    uint32_t St;

    struct
    {
        uint8_t PortSt;
        uint8_t Connect;
        uint8_t ErrHal;
    } bits;
} COM_ST_Type;

typedef struct
{
    COM_ST_Type St;

    uint16_t TimeCnt;
    uint16_t TimeSv;
    uint16_t ActTimeCnt;
    uint16_t IdleTimeCnt;
    uint16_t WaitTimeCnt;
    
    uint8_t bTimerOn;

    ComSndState_t SndSt;
    ComRcvState_t RcvSt;

    uint16_t SndSize;
    uint16_t SndCnt;
    uint16_t RcvCnt;

    uint8_t tBuff[COM_BUFF_SIZE + 4];
    uint8_t rBuff[COM_BUFF_SIZE + 4];
} com_obj_type;

#endif /* _COM_DEF_H_ */
